<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>删除文档 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/delete-doc.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/delete-doc.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/delete-doc.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/delete-doc.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="getting-started.html">基础入门</a></span>
»
<span class="breadcrumb-link"><a href="data-in-data-out.html">数据输入和输出</a></span>
»
<span class="breadcrumb-node">删除文档</span>
</div>
<div class="navheader">
<span class="prev">
<a href="create-doc.html">« 创建新文档</a>
</span>
<span class="next">
<a href="version-control.html">处理冲突 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="delete-doc"></a>删除文档<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/030_Data/35_Delete.asciidoc">edit</a>
</h2>
</div></div></div>
<p>删除文档的语法和我们所知道的规则相同，只是使用 <code class="literal">DELETE</code> 方法：</p>
<div class="pre_wrapper lang-sense">
<pre class="programlisting prettyprint lang-sense">DELETE /website/blog/123</pre>
</div>
<div class="sense_widget" data-snippet="snippets/030_Data/35_Delete_doc.json"></div>
<p>如果找到该文档，Elasticsearch 将要返回一个 <code class="literal">200 ok</code> 的 HTTP 响应码，和一个类似以下结构的响应体。注意，字段 <code class="literal">_version</code> 值已经增加:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "found" :    true,
  "_index" :   "website",
  "_type" :    "blog",
  "_id" :      "123",
  "_version" : 3
}</pre>
</div>
<p>如果文档没有找到，我们将得到 <code class="literal">404 Not Found</code> 的响应码和类似这样的响应体：</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "found" :    false,
  "_index" :   "website",
  "_type" :    "blog",
  "_id" :      "123",
  "_version" : 4
}</pre>
</div>
<p>即使文档不存在（ <code class="literal">Found</code> 是 <code class="literal">false</code> ）， <code class="literal">_version</code> 值仍然会增加。这是 Elasticsearch 内部记录本的一部分，用来确保这些改变在跨多节点时以正确的顺序执行。</p>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>正如已经在<a class="xref" href="update-doc.html" title="更新整个文档">更新整个文档</a>中提到的，删除文档不会立即将文档从磁盘中删除，只是将文档标记为已删除状态。随着你不断的索引更多的数据，Elasticsearch 将会在后台清理标记为已删除的文档。</p>
</div>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="create-doc.html">« 创建新文档</a>
</span>
<span class="next">
<a href="version-control.html">处理冲突 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>